<?php
App::uses('AppModel', 'Model');
App::uses('AuthComponent', 'Controller/Component');

class Image extends AppModel {

	/**
	* Get images of post_id
	* @author: ThanhTran
	* @since 2014-11-12
	* @return image url
	*/
	public function findById($post_id = null){
		$sql = array(
                        'conditions' => array(
                        						'post_id' => $post_id,
                        						'deleted' => 0
                        					)
					);
		return $this->find('all', $sql);
	}

	/**
	* Get number of post images
	* @author: ThanhTran
	* @since 2014-11-12
	* @return number
	*/
	public function getNumberImages($post_id = null){
		$sql = array(
                        'conditions' => array(
                        						'post_id' => $post_id,
                        						'deleted' => 0
                        					)
					);
		return $this->find('count', $sql);
	}

	/**
	* Get images by product_id
	* @author: ThanhTran
	* @since 2014-11-12
	* @return image url
	*/
	public function findByProductId($product_id = null){
		$sql = array(
                        'conditions' => array(
                        						'product_id' => $product_id
                        					),
                        'fields' => array('url','product_id')
					);
		return $this->find('all', $sql);
	}
	
	/**
	 * find all img by product id
	 *
	 * @author Quoctran
	 */
	 public function findAllByProductId($product_id = null){
		$sql = array(
                        'conditions' => array(
                        						'product_id' => $product_id,
                        						'deleted' => 0
                        					),
                        'fields' => array('id', 'url', 'product_id')
					);
		return $this->find('all', $sql);
	}
	 
	/**
	 * find all img by post id
	 *
	 * @author Quoctran
	 */
	 public function findAllByPostId($post_id = null){
		$sql = array(
	                    'conditions' => array(
	                    						'post_id' => $post_id,
	                    						'deleted' => 0
	                    					),
	                    'fields' => array('id', 'url', 'post_id')
					);
		return $this->find('all', $sql);
	}
}
?>
